local sk__kuangbi = fk.CreateSkill {

  name = "sk__kuangbi",

  tags = {},

}



sk__kuangbi:addEffect(fk.TargetSpecifying, {
  name = "sk__kuangbi",
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(sk__kuangbi.name) and data.tos and
        (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) and
        player:usedSkillTimes(sk__kuangbi.name, Player.HistoryTurn) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local players = room:askToChoosePlayers(player, {
      targets = room.alive_players,
      min_num = 1,
      max_num = #room.alive_players,
      cancelable = true,
      skill_name = "sk__kuangbi",
    })
    if #players > 0 then
      event:setCostData(self, players)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = event:getCostData(self)
    room:sortByAction(tos)
    for _, id in ipairs(tos) do
      if table.contains(data:getAllTargets(), id) then
        data:cancelTarget(id)
      else
        data:addTarget(id)
      end
    end
  end,
})

return sk__kuangbi
